package com.jack.lib;

import android.util.Log;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;
import java.nio.ByteBuffer;

/**
 * author : chong.huang
 * create : 2022/3/1
 * desc   :
 */
public class ExampleClient extends WebSocketClient {

    public ExampleClient(URI serverUri, Draft draft) {
        super(serverUri, draft);
    }

    public ExampleClient(URI serverURI) {
        super(serverURI);
    }

    @Override
    public void onOpen(ServerHandshake handshakedata) {
        send("Hello, it is me. Mario :)");
        Log.e("test", "new connection opened");
    }

    @Override
    public void onClose(int code, String reason, boolean remote) {
        Log.e("test", "closed with exit code " + code + " additional info: " + reason);
    }

    @Override
    public void onMessage(String message) {
        Log.e("test", "received message: " + message);
    }

    @Override
    public void onMessage(ByteBuffer message) {
        Log.e("test", "received ByteBuffer");
    }

    @Override
    public void onError(Exception ex) {
        Log.e("test", "an error occurred:" + ex);
    }
}